package com.lab303.powerproject.service.impl;

import com.lab303.powerproject.entity.ElectricityPrice;
import com.lab303.powerproject.repository.ElectricityPriceRepository;
import com.lab303.powerproject.service.ElectricityPriceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ElectricityPriceServiceImpl implements ElectricityPriceService {

    @Autowired
    private ElectricityPriceRepository epr;

    @Override
    public double[] getPriceEveryHour() {
        List<ElectricityPrice> eps = epr.findAll();
        double[] prices = new double[24];
        String rets[] = eps.get(0).getPrice().split(",") ;
        for(int i = 0;i<rets.length;++i)prices[i] = Double.parseDouble(rets[i]);
        return prices;
    }
}
